package com.reading.controller;

import com.github.pagehelper.PageInfo;
import com.reading.pojo.Recharge;
import com.reading.pojo.web.Banner;
import com.reading.service.BannerService;
import com.reading.vo.Rmed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    @RequestMapping("findbanner")
    public Rmed findbanner(@RequestBody Banner banner,Integer pageNo,Integer pageSize){
        PageInfo pageInfo = bannerService.findbanner(banner,pageNo,pageSize);
        return Rmed.suceessData(pageInfo);
    }

    @RequestMapping("list")
    public List<Banner> list(){
        return bannerService.list();
    }

    @RequestMapping("add")
    public Rmed add(@RequestBody Banner banner){
        try {
            if (banner.getId()==null){
                bannerService.add(banner);
            }else {
                bannerService.update(banner);
            }
            return Rmed.suceessData("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rmed.error("添加失败");
    }
    @RequestMapping("delete")
    public Rmed delete(Integer id){
        try {
            bannerService.delete(id);
            return Rmed.suceessData("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rmed.error("删除失败");
    }
}
